package com.hnucm.onlinealgstudy.controller;

import com.hnucm.onlinealgstudy.pojo.ColParams;
import com.hnucm.onlinealgstudy.pojo.Collect;
import com.hnucm.onlinealgstudy.service.CollectService;
import com.hnucm.onlinealgstudy.utils.ResultOBJ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/oasadapi/collect")
public class CollectController {
    @Autowired
    CollectService collectService;

//    根据用户id获取收藏列表
//    @GetMapping
//    public List<Collect> getCollection(@RequestParam Integer id){
//        return ;
//    }

    // 收藏习题
    @PostMapping
    public ResultOBJ collectExe(@RequestBody Collect collect){
        try {
            collectService.addCollect(collect);
            return ResultOBJ.ADD_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.ADD_ERROR;
        }
    }

    // 根据指定条件查找收藏习题
    @PutMapping
    public List<Collect> findCollection(@RequestBody ColParams colParams){
        return collectService.findCollect(colParams);
    }

    // 取消收藏
    @DeleteMapping(value = "/{id}")
    public ResultOBJ deleteCollection(@PathVariable Integer id){
        try {
            collectService.deleteCollection(id);
            return ResultOBJ.DELETE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.DELETE_ERROR;
        }
    }
}
